#  
#  All rights reserved.  This computer program and related documentation
#  is protected by copyright and distributed under licenses restricting
#  its use, copying, distribution and decompilation.  This computer
#  program and its documentation are CONFIDENTIAL and a TRADE SECRET
#  of EMULEX CORPORATION.  The receipt or possession of this program
#  or its documentation does not convey rights to reproduce or disclose
#  its contents, or to manufacture, use, or sell anything that it may
#  describe, in whole or in part, without the specific written consent
#  of EMULEX CORPORATION.  Any reproduction of this program without
#  the express written consent of EMULEX CORPORATION is a violation
#  of the copyright laws and may subject you to criminal prosecution.
# 

device_id_string=$1
major_minor=""
major=""
minor=""
udev_device_name=""
match=""

#echo $device_id_string

# find device in sysfs directory
for i in `ls /sys/class/scsi_device`
do
#    echo $i 
    if [ -f /sys/class/scsi_device/$i/device/block/dev ];then
       match=`cat /sys/class/scsi_device/$i/device/block/dev`
#        echo $(cat /sys/class/scsi_device/$i/device/block/dev)
#        echo $match
#        echo $device_id_string 
        if [ "$device_id_string" = "$i" ];then
#            echo "match"            
            major_minor=$match
        fi
    #else
    #    if [ -f /sys/class/scsi_device/$i/device/generic/dev ];then
    #        match=`cat /sys/class/scsi_device/$i/device/generic/dev`
#   #        echo $(cat /sys/class/scsi_device/$i/device/block/dev)
#   #         echo $match
#   #         echo $device_id_string 
    #        if [ "$device_id_string" = "$i" ];then
#   #            echo "match"
    #           major_minor=$match
    #        fi
    #    fi
    fi
done

if [ -n "$major_minor" ];then
#   echo "here is result: $major_minor"
   major=`echo $major_minor | awk -F: '{ print $1 }'`
#   echo "here is major: $major"
   minor=`echo $major_minor | awk -F: '{ print $2 }'`
#   echo "here is minor: $minor"

   # now look in UDEV directory for matching device
   udev_device_name=`ls -l /dev | egrep "^b.*[[:space:]]$major,[[:space:]]*$minor[[:space:]]" | awk '{ print $10 }'`
   echo -n "$udev_device_name"
else
   echo -n " "
fi

